package com.tms.common;

import lombok.Data;

import java.io.Serializable;

/**
 * Author：潘建冰
 * Package：com.taskmanagesystem.common
 * Project：TaskManageSystem
 * name：R
 * Date：2025/3/24  20:39
 */

@Data
public class Result<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;

    private Result() {}

    // 成功返回结果
    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    // 失败返回结果
    public static <T> Result<T> error() {
        return error(ResultCode.FAIL.getMessage());
    }

    public static <T> Result<T> error(String message) {
        return error(ResultCode.FAIL.getCode(), message);
    }

    public static <T> Result<T> error(Integer code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
